package com.sec.typhoondatapush.config;

import com.sec.typhoondatapush.entity.JobConfig;
import com.sec.typhoondatapush.util.TaskUtils;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

/**
 * JobFactory用反射的方法动态获取job_config数据库记录的job存放的class和方法去执行job
 *
 * @date :Create in  2018/7/30- 15:11
 * @Version: V1.0
 * @author: zhuwq
 */

/** 不能并发执行同一个Job */
@DisallowConcurrentExecution
public class QuartzJobFactory implements Job {

    public static final String SCHEDULEJOBKEY = "scheduleJob";

    /**execute会根据cron的规则进行执行*/
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        JobConfig jobConfig = (JobConfig) jobExecutionContext.getMergedJobDataMap().get(SCHEDULEJOBKEY);
        TaskUtils.invokMethod(jobConfig);
    }

}
